package com.jdbc.student;

import java.util.Scanner;

/**
 * 测试类  v1.0
 * @author Enginner-Jie
 */
public class Test {
	public static void main(String[] args) {
		
		Student stu = new Student();
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		System.out.println("插入记录--1,查询记录--2,删除记录--3");
		int choice = sc.nextInt();
		//插入记录
		if (choice == 1) {
			System.out.println("-------插入记录--------");
			System.out.println("请输入考生信息：");
			System.out.println("4 Or 6 ?");
			stu.setType(sc.nextInt());
			
			System.out.println("IDCard:");
			stu.setIDCard(sc.next());
			
			System.out.println("ExamCard:");
			stu.setExamCard(sc.next());
			
			System.out.println("StudentName:");
			stu.setStudentName(sc.next());
			
			System.out.println("Location:");
			stu.setLocation(sc.next());
			
			System.out.println("Grade:");
			stu.setGrade(sc.nextInt());
			
			String insertInfo = "INSERT examstudent (Type,IDCard,ExamCard,StudentName,Location,Grade) VALUES ("
					+stu.getType()+","
					+"'"+stu.getIDCard()+"',"
					+"'"+stu.getExamCard()+"',"
					+"'"+stu.getStudentName()+"',"
					+"'"+stu.getLocation()+"',"
					+stu.getGrade()+");";
			
			Function.update(insertInfo);
			System.out.println("添加记录成功!");
			String Info = "SELECT * from examstudent WHERE IDCard = '"+stu.getIDCard()+"'";
			Function.query(Info);
			
		//查询成绩	
		} else if (choice == 2) {
			System.out.println("-------成绩查询--------");
			System.out.println("按学号查询--1,按准考证号查询--2");
			int kind =sc.nextInt();
			if (kind == 1) {
				System.out.println("请输入学号：");
				String queryInfo = "SELECT * from examstudent WHERE IDCard = '"+sc.next()+"'";
				Function.query(queryInfo);
			} else if (kind == 2) {
				System.out.println("请输入准考证号：");
				String queryInfo = "SELECT * from examstudent WHERE ExamCard = '"+sc.next()+"'";
				Function.query(queryInfo);
			}else{
				System.out.println("输入错误！");
			}
		//删除记录	
		}else if (choice == 3){
			System.out.println("-------删除记录--------");
			System.out.println("输入要删除的记录学号：");
			String delInfo = "DELETE from examstudent WHERE IDCard = '"+sc.next()+"'";
			Function.update(delInfo);
			System.out.println("删除成功!");
		}else {
			System.out.println("输入错误！");
			throw new RuntimeException();  //抛出一个运行异常，中断程序。
		}
	}
}
